﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace mars_client.csharp.util
{
    class SysUtil
    {
        public string getInternalIP()
        {
            IPHostEntry host;
            string localIP = "?";
            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ip in host.AddressList)
            {
                if(ip.AddressFamily.ToString() == "InterNetwork")
                {
                    localIP = ip.ToString();
                    break;
                }
            }
            return localIP;
        }
        /// <summary>
        /// 创建人   : Cecil0o0
        /// 电子邮箱 : jiegithub@gmail.com
        /// 创建时间 : 2016-2-27
        /// 功能描述 : 根据uri创建bitmapSource对象并返回
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public static BitmapImage generateImgSource(string uri)
        {
            DirectoryInfo rootDir = Directory.GetParent(Environment.CurrentDirectory);
            string root = rootDir.Parent.FullName;
            BitmapImage bmp = new BitmapImage();
            bmp.BeginInit();//初始化
            bmp.UriSource = new Uri(root + uri);//设置图片路径
            bmp.EndInit();//结束初始化
            return bmp;
        }

        public static BitmapImage netImageSource(string uri)
        {
            BitmapImage bmp = new BitmapImage();
            bmp.BeginInit();//初始化
            bmp.UriSource = new Uri(uri);//设置图片路径
            bmp.EndInit();//结束初始化
            return bmp;
        }
    }
}
